
<%def name="item_actions(item)">
    <div class="actionbar" style="height:34px; ">
        <div class="boxlinks_tabs boxlinks right"  style="margin-top:-4px;">
            <a href="javascript:void(0)" id="sorttab" class="current">Sort</a>
            <a href="javascript:void(0);" id="editfolder" objid="${(item and item.id) or '0'}">
            <img  alt="Edit Folder" src="/images/icon_edit.png" style="vertical-align: bottom;" border="0" />
                Edit Folder</a>
            <a href="javascript:void(0);" id="addcontentitem" objid="${(item and item.id) or '0'}">
            <img  alt="Add New Content" src="/images/icon_add.png" style="vertical-align: bottom;" border="0" />
                Add New Content</a>
            <a href="javascript:void(0);" id="addfolder" objid="${(item and item.id) or '0'}">
            <img  alt="Add New Folder" src="/images/icon_add.png" style="vertical-align: bottom;" border="0" />
                Add new Folder</a>
        </div>
    </div>
</%def>
<%def name="view(item,edit=False, show_details=False)">
    <div id="cmsitem_${item.id}" class="nodedisplay clearfix">
        <div class="content_block">
            <a href="#" class="title">${item.title}</a>

            % if c.user and edit:
                <a href="#" onclick="DS.cmsedit(${item.id});" class="edit">Edit</a>
            % endif

            % if show_details:
                <p class="description">
                    ${h.simple_format(item.content)}
                </p>
            % endif

        </div>
    </div>
</%def>

<%def name="treeview(node,edit=False,isroot=False)">

    % if node and node.children and len(node.children) > 0:
        <li id="cmsitem_${node.id}">
            <span class="folder"><a href="javascript:void(0);" objid="${node.id}" class="folderlink" id="item${node.id}" src="">${node.title}</a></span>
            <ul id="list${node.id}">
            % for itemassoc in node.children:
                ${treeview(itemassoc.item,edit=True)}
            % endfor
            </ul>
        </li>
    % elif node and node.item_type != 'folder':
        <li><span class="file"  objid="${node.id}"  id="item${node.id}">
            ${h.truncate(node.title, length=30, truncate_string='...')}</span></li>
    % elif node and node.item_type == 'folder':
        <li id="cmsitem_${node.id}"><span class="folder empty"  objid="${node.id}"> 
                <a href="javascript:;" objid="${node.id}" id="item${node.id}" class="folderlink" src="" >
                    ${h.truncate(node.title, length=30, truncate_string='...')}
                </a>
            </span>
        </li>
    % else:
        whoops, that should n't happen
    % endif

</%def>
<%def name="list(cmsitems,edit=False)">
    % for itemassoc in cmsitems:

        ${view(itemassoc.item,edit)}

    % endfor
</%def>

<%def name="form(item)">
    <style type="text/css">
    .formbox input {width:350px!important; }
    textarea {width:350px!important; }
    .formbox .actions input {width:100px!important; }
    </style>
    <div class="formbox main_form">
        <div class="boxlinks_tabs boxlinks actionbar">
            <a href="#tab1"  class="current">Main</a>
            <a href="#tab2">More</a>
            <a href="#tab3" id="embedtab">How to Embed</a>
        </div>
        <div class="tab-spacer"></div>

            ${h.form(h.url(action='addupdate'), method='post', id="cmsform")}
                <input type="hidden" id="objectid" name="objectid" value="${(item and item.id) or '0'}">
                <input type="hidden" id="parentid" name="parentid" value="${(c.folder and c.folder.id) or '0'}">
                <input type="hidden" id="rid" name="rid" value="${(item and item.rid) or ''}">
                <input type="hidden" id="item_type" name="item_type" value="${(c.item and c.item.item_type) or 'cms'}">
                <br />
                <fieldset style="" id="tab1">
                    <!--<legend>Content Authoring</legend>-->
                    <div class="required">
                        <label for="title">Title:</label>
                        ${h.text_field('title', value=(item and item.title) or '')}
                    </div>

                    <div class="required" id="keysection" style="display:show;">
                        <label for="key">Key:</label>
                        <small>The key is a url safe string to use in your app to request
                            this item</small>
                        ${h.text_field('key', value=(item and item.key) or '')}
                    </div>
                    <div class="optional">
                        <label for="content">Content:</label>
                        ${h.text_area("content", content=(item and item.content) or '', size="40x6")}
                    </div>
                    <div class="optional">
                        <label for="content2">Extended Content:</label>
                        ${h.text_area("content2", content=(item and item.content2) or '', size="40x6")}
                    </div>
                    <div class="optional">
                        <label for="url">url:</label>
                        ${h.text_field('url', value=(item and item.url) or '')}
                    </div>
                    <div class="optional">
                        <label for="tags">Tags:</label>
                        ${h.text_field('tags', value=(item and item.tags) or '')}
                    </div>

                    <strong>Bold</strong> fields are required.
                </fieldset>
                <fieldset style="display:none;" id="tab2">
                    <legend>Content Authoring</legend>
                    <strong>Bold</strong> fields are required.
                    <div class="instructions">Create a Content item which is available over web services as html or xml</div>
                    <div class="required">
                        <label for="title2">Title2:</label>
                        ${h.text_field('title2', value=(item and item.title) or '')}
                    </div>

                    <div class="required" id="keysection" style="display:show;">
                        <div class="instructions">The key is a url safe string to use in your app to request
                            this item</div>
                        <label for="key2">Key2:</label>
                        ${h.text_field('key2', value=(item and item.key) or '')}
                    </div>
                </fieldset>
                <div style="display:none;"  id="tab3">
                    
                    <b>See API Results</b> <a href="/api/html/cms/${((item and item.rid) or '')}" >Html</a>, 
                        <a href="/api/xml/cms/${((item and item.rid) or '')}" >Xml</a>
                    
                    <br /><br />
                    <b>In Pylons</b>
                    <br />
                    &#36;{h.remote_html('${((item and item.rid) or '')}')}
                    
                    <br /><br />
                    <b>In Dotnet </b> <a href="http://code.google.com/p/demisauce/source/browse/demos/DotNetWeb/Web.config">See web.config</a>
                    <pre>
                    
${h.html_encode("""<DS:CmsitemControl resource="blog" max="1" random="true" runat="server">
    <ContentTemplate>
      <div>
          <h2><%# Container.Title %></h2>
      	  <p><%# Container.Created.ToString("MMM dd, yyyy")%></p>
          <p><%# Container.Content %></p>
      </div>
    </ContentTemplate>
</DS:CmsitemControl>""").replace("blog",((item and item.rid) or ''))}
                    </pre>
                    <b></b>
                </div>
                <div class="actions"><input type="submit" class="primary" id="submit" value="Save &#187;">
                &nbsp;&nbsp;<a href="#" id="cancelcmsform">cancel</a></div>

            ${h.end_form()}
    </div>
    <script type="text/javascript">
        $(document).ready(function() {
            //$('#container-1').tabs();
            var currentTab = '#tab1';
            $("div.boxlinks a").click(function() {
                $(this).parent().children().each(function(i) {
                    $(this).removeClass('current');
                });
                $(currentTab).hide();
                $(this.hash).show();
                $(this).addClass('current');
                currentTab = this.hash;
            });
            $("#title").blur(function() {
                key = $("#key").attr('value');
                if (key == null || key.length < 3) {
                    $.post("/cms/keygen/", { title: $("#title").attr('value')},function(data){
                        $("#key").attr('value',data);
                        $('#keysection').show();
                    });
                }
            });
            $("#cancelcmsform").click(function() {
                //$('#accountform').hide();
                //$('#profilesettings').show();
            });
        });
    </script>
</%def>
